﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using MockSchoolManagement.Domain.Students
@using MockSchoolManagement.Core.Repositories
@model MockSchoolManagement.Mvc.ViewModel.StudentCreateViewModel
@inject IRepository<Student,int> _Repository
@{
    ViewBag.Title = "创建学生信息";
}

@* 上传文件时请记得给Form表单添加 enctype="multipart/form-data" *@

<form enctype="multipart/form-data" asp-controller="home" asp-action="Create" method="post" class="mt-3">
    <div asp-validation-sumary="All" class="text-danger"></div>
    
    <div class="form-group row">
        <label asp-for="Name" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Name" class="form-control" placeholder="请输入名字"/>
            <span asp-validation-for="Name" class="text-danger"></span>
        </div>

    </div>
    <div class="form-group row">
        <label asp-for="Email" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <input asp-for="Email" class="form-control" placeholder="请输入邮箱地址"/>
            <span asp-validation-for="Email" class="text-danger"></span>
        </div>
    </div>
    <div class="form-group row">
        <label asp-for="Photos" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-10">
            <div class="custom-file">
                <input asp-for="Photos" multiple class="form-control custom-file-input"/>
                <label class="custom-file-label">请选择图片....</label>
            </div>
        </div>
    </div>
    <div class="form-group row">
        <div class="col-sm-10">
            <button type="submit" class="btn btn-primary">创建</button>
        </div>
    </div>

    <div class="form-group row">
        <div class="col-sm-10">
            学生总人数=@_Repository.Count().ToString()
        </div>
    </div>
    @section Scripts
    {
        <script>
            $(document).ready(function() {
                $(".custom-file-input").on("change",
                    function() {
                        var fileLabel = $(this).next(".custom-file-label");

                        var files = $(this)[0].files;
                        if (files.length>1) {
                            fileLabel.html("读者已经选择了："+files.length+"个文件");
                        } else if (file.length==1) {
                            fileLabel.html(files[0].name);
                        }
                    });
            })
        </script>
    }
</form>
